package enemies.factory.builders;

import java.net.URL;
import java.util.Random;

import com.jme.scene.Node;
import com.model.md5.controller.MD5Controller;
import com.model.md5.importer.MD5Importer;
import com.model.md5.interfaces.IMD5Animation;
import com.model.md5.interfaces.IMD5Node;

import enemies.strategy.concretes.ConcreteStrategyMed;

/** "ConcreteBuilder" */
public class AltairEnemyBuilder extends EnemyBuilder {

	private MD5Controller bodyController;

	@Override
	public void asignarEstrategia() {
		getEnemy().setStrategy(new ConcreteStrategyMed(mapControl, getEnemy()));
		
	}

	@Override
	public void buildModel() {
		String dir = "data/model/Altair/";
		URL md5mesh = getClass().getClassLoader().getResource(
				dir + "mesh.md5Mesh");
		URL animWalk = getClass().getClassLoader().getResource(
				dir + "floating.md5Anim");
//		URL animVictory = getClass().getClassLoader().getResource(
//				dir + "victory.md5Anim");
		
		
		MD5Importer importer = new MD5Importer();
		
		IMD5Node body = null;
		IMD5Animation walk = null;
//		IMD5Animation victory = null;
		try {

			importer.loadMesh(md5mesh, "ModelNode");
			body  = importer.getMD5Node();
			
			
			importer.loadAnim(animWalk, "floating");
			walk = importer.getAnimation();

		//	importer.loadAnim(animVictory, "victory");
		//	victory = importer.getAnimation();
	//		
			
			}
		catch (Exception e) {
			// TODO: handle exception
		}
		bodyController = new MD5Controller(body);
		bodyController.addAnimation(walk);
		//bodyController.addAnimation(victory);
		
		bodyController.setActive(true);
		bodyController.setRepeatType(1);
		bodyController.setSpeed(1f);

		body.addController(bodyController);
		
		Node model = (Node) body;
		

		model.setLocalScale(.7f);
		model.setLocalTranslation(0,2,0);
		
		getEnemy().getNode().attachChild(model);

	}

	@Override
	public void buildTexture() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void locate() {

		Random rnd = new Random();

		int row = rnd.nextInt(mapControl.getWide()- 5)+5;
		int col = rnd.nextInt(mapControl.getHight() -5) +5  ;
				
			while (!mapControl.isEmpty(row, col)) {
			row = rnd.nextInt(mapControl.getWide() ) ;
			col = rnd.nextInt(mapControl.getHight()) ;
			
		}

			getEnemy().locate(row,col);
			

			

		
	}

	@Override
	public void setName() {
		getEnemy().setName("Altari");
		
	}
}